/*
	File:		Enemy.h
	Author:		Ben Feldmann
	Purpose:	Base class for game enemies
*/


#pragma once


#include "Entity.h"
#include "IListener.h"
#include "Player.h"
#include "Emitter.h"
#include "EmitterManager.h"

class Event;


class Enemy : public Entity, public IListener
{
private:
	float maxHealth;
	float health;
	float moveSpeed;
	int scrapMetal;
	int circuitry;
	unsigned char difficulty;
	float attackTimer;

	Player* player;

	float prevX;
	float prevY;
	bool collided;
	int roomNum;

	// Timer for stun
	float stunTimer;
	// time stunned for
	float stunned;

	float dotTimer;
	float dotRate;
	float curDot;
	float dotDuration;
	float dotDamage;

	bool slowed;
	float slowTimer;
	float slowDuration;
	float prevSpeed;

protected:
	bool disabled;
	bool hit;

	Emitter* deathEm;
	Emitter* damageEm;
	Emitter* dotEm;
	Emitter* stunEm;

	EmitterManager* em;

	
public:
	Enemy();

	virtual ~Enemy();

	virtual int GetMax() {return (int)health;}

	virtual void Update(float elapsed);

	virtual void Render();

	virtual RECT GetRect();

	//virtual bool CheckCollision(IEntity* base);

	virtual void Attack();

	// Pure virtual method from IListener
	virtual void HandleEvent(Event* thisEvent);

	// Accessors
	float			GetMaxHealth() const	{return maxHealth;}
	float			GetHealth() const		{return health;}
	float			GetSpeed() const		{return moveSpeed;}
	int				GetMetal() const		{return scrapMetal;}
	int				GetCircuitry() const	{return circuitry;}
	unsigned char	GetDifficulty() const	{return difficulty;}
	float			GetAttackTimer() const	{return attackTimer;}
	virtual Player*	GetPlayer() const		{return player;}
	float			GetPrevX() const		{return prevX;}
	float			GetPrevY() const		{return prevY;}
	bool			GetCollided() const		{return collided;}

	// Mutators
	void SetMaxHealth(float h)				{maxHealth = h;}
	void SetHealth(float h)					{health = h;}
	void SetSpeed(float s) 					{moveSpeed = s;}
	void SetMetal(int m) 					{scrapMetal = m;}
	void SetCircuitry(int c)				{circuitry = c;}
	void SetDifficulty(unsigned char d)		{difficulty = d;}
	void SetAttackTimer(float a)			{attackTimer = a;}
	void SetPrevX(float x)					{prevX = x;}
	void SetPrevY(float Y)					{prevY = Y;}
	void SetCollided(bool c)				{collided = c;}
	void SetSlow(float time, float spdReduc)
	{
		if(slowed == false)
		{
			prevSpeed = GetSpeed();
		}
		spdReduc = 1 - spdReduc;
		slowed			= true;
		slowDuration	= time;
		slowTimer		= 0;
		SetSpeed(prevSpeed * spdReduc);
		
	}
	void SetDOT(float time, float damage, float rate)
	{
		dotTimer	= 0;
		dotDuration = time;
		dotDamage	= damage;
		dotRate		= rate;
		curDot		= 0;

	}
	void SetStunTime(float time)
	{
		stunned = time;
		stunTimer = 0;
		disabled = true;
	}

	int GetRoomNum(void) {return roomNum;}
	void SetRoomNum(int num) {roomNum = num;}
	
};
